package com.health.controller;

import com.health.constant.ResultCodeConstant;
import com.health.pojo.domain.MedicalRecordDO;
import com.health.pojo.dto.CreateGroup;
import com.health.pojo.dto.DeleteGroup;
import com.health.pojo.dto.MedicalRecordDTO;
import com.health.pojo.dto.RestResult;
import com.health.pojo.dto.UpdateGroup;
import com.health.pojo.query.MedicalRecordQuery;
import com.health.pojo.query.QueryGroup;
import com.health.service.MedicalRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.lang.Boolean;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * MedicalRecordController
 *
 * @author WUYU_MIN
 * @date 2025-04-29 23:51:18
 */
@Tag(name = "MedicalRecordController")
@RequestMapping("medical-record")
@RestController
public class MedicalRecordController {
    @Autowired
    private MedicalRecordService medicalRecordService;

    /**
     * add
     *
     * @param medicalRecordDTO 医疗记录入参实体类
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @Operation(summary = "add")
    @ResponseBody
    public RestResult<Boolean> addMedicalRecord(@RequestBody @Validated(CreateGroup.class) MedicalRecordDTO medicalRecordDTO) {
        Boolean result = medicalRecordService.addMedicalRecord(medicalRecordDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * delete
     *
     * @param medicalRecordDTO 医疗记录入参实体类
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @Operation(summary = "delete")
    @ResponseBody
    public RestResult<Boolean> deleteMedicalRecord(@RequestBody @Validated(DeleteGroup.class) MedicalRecordDTO medicalRecordDTO) {
        Boolean result = medicalRecordService.deleteMedicalRecord(medicalRecordDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * update
     *
     * @param medicalRecordDTO 医疗记录入参实体类
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @Operation(summary = "update")
    @ResponseBody
    public RestResult<Boolean> updateMedicalRecord(@RequestBody @Validated(UpdateGroup.class) MedicalRecordDTO medicalRecordDTO) {
        Boolean result = medicalRecordService.updateMedicalRecord(medicalRecordDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * info
     *
     * @param medicalRecordQuery 医疗记录查询入参实体类
     * @return
     */
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    @Operation(summary = "info")
    public RestResult<List<MedicalRecordDO>> queryMedicalRecord() {

        List<MedicalRecordDO> result = medicalRecordService.queryMedicalRecord();
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * queryMedicalRecordsByUserId
     *
     * @param userId 用户ID
     * @return 该用户下的所有医疗记录
     */
    @RequestMapping(value = "/list-by-user-id", method = RequestMethod.GET)
    @Operation(summary = "queryMedicalRecordsByUserId")
    @ResponseBody
    public RestResult<List<MedicalRecordDO>> queryMedicalRecordsByUserId(@RequestParam Integer userId) {
        List<MedicalRecordDO> results = medicalRecordService.queryMedicalRecordsByUserId(userId);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, results);
    }
}
